package ${packageCode}.api.vx.${moduleMapperCode}.${(businessCode?uncap_first)!''}

import org.apache.commons.lang3.StringUtils
import ${packageCode}.${moduleMapperCode}.service.${businessCode}Service
import top.cardone.context.ApplicationContextHolder
import top.cardone.core.CodeException

class c0001 implements java.io.Serializable {
    def input(input) {
        def newInput = [:]

<#if entityMapper.fieldMapperMap??>
    <#list entityMapper.fieldMapperMap?values as fieldMapper>
		newInput?.${fieldMapper.code} = input?.${fieldMapper.code}
    </#list>
</#if>

        newInput.flagCode = StringUtils.defaultIfBlank(input.flagCode, "input")

        newInput
    }

    def validation(input) {
//      if (StringUtils.isBlank(input?.${(businessCode?uncap_first)!''}Code)) {
//          throw new CodeException("${(businessCode?uncap_first)!''}Code required", "${businessName}编号必填")
//      }
//
//      if (StringUtils.length(input?.${(businessCode?uncap_first)!''}Code) < 4) {
//          throw new CodeException("${(businessCode?uncap_first)!''}Code minlength", "${businessName}编号需{0}个字符以上", 4)
//      }
//
//      if (StringUtils.length(input?.${(businessCode?uncap_first)!''}Code) > 255) {
//          throw new CodeException("${(businessCode?uncap_first)!''}Code maxlength", "${businessName}编号需小于{0}个字符", 255)
//      }
//
//      if (StringUtils.isBlank(input?.name)) {
//          throw new CodeException("name required", "${businessName}名称必填")
//      }
//
//      if (StringUtils.length(input?.name) < 4) {
//          throw new CodeException("name minlength", "${businessName}名称需{0}个字符以上", 4)
//      }
//
//      if (StringUtils.length(input?.name) > 255) {
//          throw new CodeException("name maxlength", "${businessName}名称需小于{0}个字符", 255)
//      }
		
		def readOne = ['${(businessCode?uncap_first)!''}Code': input.${(businessCode?uncap_first)!''}Code, "dataStateCode": "1"]

		def count = ApplicationContextHolder.getBean(${businessCode!''}Service.class).readOne(Integer.class, readOne)

		if (count > 0) {
			throw new CodeException("${(businessCode?uncap_first)!''}Code already exists", "${businessName}编号已经存在")
		}
    }

    def func(input) {
		ApplicationContextHolder.getBean(${businessCode!''}Service.class).insertByNotExistsCache(input)
    }

    def output(output) {
		['insertCount': output]        
    }
}